<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

</body>
<script>
    function createObjectURL(object) {
        return (window.URL) ? window.URL.createObjectURL(object) : window.webkitURL.createObjectURL(object);
    }
    var xhr = new XMLHttpRequest();
    var formData = new FormData();
    xhr.open('get', 'http://127.0.0.1:4567/qujing/jinyangqu/apis/tasks/excel?startTime=&endTime=&farmStatus=&status=&keywords=');  //url填写后台的接口地址，如果是post，在formData append参数（参考原文地址）
    xhr.setRequestHeader("Content-Type", "application/json;charset=utf-8");
    xhr.setRequestHeader("Authentication", "Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJ7XCJ1c2VyTmFtZVwiOlwiMTIzNDU2XCIsXCJwaG9uZVwiOlwiMjEyXCIsXCJwb3NpdGlvblwiOlwiMTIxXCIsXCJkZXBhcnRtZW50XCI6XCIxMlwiLFwicm9sZVwiOlwiUk9MRV9VU0VSLFJPTEVfQURNSU5cIixcInJlZ2lvbkNvZGVcIjoxMixcImlkXCI6MSxcImRlbEZsYWdcIjp0cnVlLFwiY3JlYXRlRGF0ZVwiOntcImRhdGVcIjp7XCJ5ZWFyXCI6MjAxOSxcIm1vbnRoXCI6MyxcImRheVwiOjE4fSxcInRpbWVcIjp7XCJob3VyXCI6MTcsXCJtaW51dGVcIjozMixcInNlY29uZFwiOjM2LFwibmFub1wiOjM3MzAwMDAwMH19fSIsImV4cCI6MTU1MzY3MzY1OX0.03QFe6aeuCdpFK7CCBmArV1TUpViWcNt9aEMMegpgUxSEBJFKaQ8JHsAolr7K78pg5gtIn2U-5AC4yu9Xbc43w");
    xhr.responseType = 'blob';
    xhr.onload = function (e) {
        if (this.status == 200) {
            var blob = this.response;
                        var responseHeader = this.getResponseHeader("Content-Disposition");
                        console.log(responseHeader)
            // 中文名???
            var filename = this.getResponseHeader("Content-Disposition").split(";")[1].split("filename=")[1];
            var fileNameUnicode = this.getResponseHeader("Content-Disposition").split("filename*=")[1];
            console.log(filename)
            console.log(fileNameUnicode)
            if (fileNameUnicode) {//当存在 filename* 时，取filename* 并进行解码（为了解决中文乱码问题）
                filename = decodeURIComponent(fileNameUnicode);
            }
            console.log(filename);
           // var filename = blob.headers("Content-disposition").split(";")[1].split("filename=")[1];

            console.log(this.response)
            if (window.navigator.msSaveOrOpenBlob) {
                navigator.msSaveBlob(blob,filename);
            } else {
                var a = document.createElement('a');
                var url = createObjectURL(blob);
                a.href = url;
                a.download = filename;
                document.body.appendChild(a);
                a.click();
                window.URL.revokeObjectURL(url);
            }

        }
    };
    xhr.send(formData);
    console.log("end")
</script>

</html>